<template>
  <div class="dialog">
    <el-dialog
      :title="'维修联系人'+titleText"
      :visible.sync="showDialog"
      width="35%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        class="el-form"
      >
        <el-form-item label="联系人名称:" class="w100p">
          <el-input
            v-model="formData.alarmContactName"
            clearable
          />
        </el-form-item>
        <el-form-item label="邮箱:" class="w100p">
          <el-input
            v-model="formData.email"
            clearable
          />
        </el-form-item>
        <el-form-item label="电话:" class="w100p">
          <el-input
            v-model="formData.phone"
            clearable
          />
        </el-form-item>
        <el-form-item label="微信:" class="w100p">
          <el-input
            v-model="formData.weChat"
            clearable
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import alarmContactManagementApi from "@/api/monitoring-alarm/alarm-contact-management";

export default {
  name: '',
  components: { },
  props: {
    // 弹框名称
    titleText: {
      type: String,
      default: ""
    },
    nowChanceStau: {
      type: String,
      default: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      formData: {},
      showDialog: this.show
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
    },
    nowChanceStau(v) {
      if (v === 'add') {
        this.formData = {}
      }
      if (v === 'edit') {
        this.formData = this.editObject
      }
    }
  },
  created() {
    // this.queryEquipType()
  },
  mounted() {
  },
  methods: {
    save() {
      if (this.nowChanceStau === 'edit') {
        // 编辑接口
        // this.formData.routePointMapperList = this.tagsList;
        alarmContactManagementApi.editlist(this.formData).then(res => {
          if (res.code === 1) {
            this.$message.success("修改成功！");
            this.getTableDataList();
          } else {
            this.$message.error(res.msg);
          }
        });
      } else if (this.nowChanceStau === 'add') {
        alarmContactManagementApi.addlist(this.formData).then(res => {
          if (res.code === 1) {
            this.$message.success(res.msg);
            this.getTableDataList();
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
    close() {
      this.$emit("closeDialog");
    },
    cancel() {
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
